package org.HisCanvas.ChrisRiffle.JFlightLog.common;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.HisCanvas.ChrisRiffle.JFlightLog.dataModel.LogBookRec;
import org.HisCanvas.ChrisRiffle.JFlightLog.persist.LogBookDbConstants;

/**
 * LogBookRecUtils
 * 
 * @author RIF
 */
public class LogBookRecUtils implements LogBookDbConstants {

    
    private static Map<String, String> columnNameToShortNameMap;

    
    
    /**
     * getColumnNameToShortNameMap
     * @return
     */
    private static Map<String, String> getColumnNameToShortNameMap() {
	
		if (columnNameToShortNameMap == null) {
	
		    columnNameToShortNameMap = new HashMap<String, String>(
			    DEFAULT_COLUMN_DISPLAY_ORDER_LIST.size());
		    
			columnNameToShortNameMap.put(REMARKS, "RMK");
	
			columnNameToShortNameMap.put(TOTAL_HOURS, "TOT");
			columnNameToShortNameMap.put(SOLO, "SOL");
			columnNameToShortNameMap.put(SECOND_IN_COMMAND_HOURS, "SIC");
			columnNameToShortNameMap.put(PILOT_IN_COMMAND_HOURS, "PIC");
			columnNameToShortNameMap.put(DUAL_INSTRUCTION_GIVEN_HOURS, "DUAL GVN");
			columnNameToShortNameMap.put(DUAL_INSTRUCTION_RECEIVED_HOURS, "DUAL RCVD");
			columnNameToShortNameMap.put(SIMULATOR_HOURS, "SIM");
			columnNameToShortNameMap.put(SAFETY_PILOT_NAME, "SFTY PLT");
			columnNameToShortNameMap.put(INSTRUMENT_APPROACHES_NAMES, "IAP NAMES");
			columnNameToShortNameMap.put(INSTRUMENT_APPROACHES_COUNT, "IAP #");
			columnNameToShortNameMap.put(INSTRUMENT_SIMULATED_HOURS, "SIM INS");
			columnNameToShortNameMap.put(INSTRUMENT_ACTUAL_HOURS, "ACT INS");
			columnNameToShortNameMap.put(NIGHT_HOURS, "NIGHT");
			columnNameToShortNameMap.put(DAY_HOURS, "DAY");
			columnNameToShortNameMap.put(CROSS_COUNTRY_HOURS, "XCNTRY");
			columnNameToShortNameMap.put(MULTI_ENGINE_HOURS, "MULTI");
			columnNameToShortNameMap.put(SINGLE_ENGINE_HOURS, "SEL");
			columnNameToShortNameMap.put(LANDINGS_NIGHT_COUNT, "LDGS NIGHT");
			columnNameToShortNameMap.put(LANDINGS_DAY_COUNT, "LDGS DAY");
			columnNameToShortNameMap.put(LANDINGS_TOTAL_COUNT, "LDGS TOT");
			columnNameToShortNameMap.put(ARRIVAL_AIRPORT_CODE, "TO");
			columnNameToShortNameMap.put(DEPARTURE_AIRPORT_CODE, "FROM");
			columnNameToShortNameMap.put(AIRCRAFT_REGISTRATION, "REG");
			columnNameToShortNameMap.put(AIRCRAFT_TYPE, "TYP");
			columnNameToShortNameMap.put(DATE_OF_FLIGHT, "DAT");
		}
		
		return columnNameToShortNameMap;

    }

    
	/**
	 * 
	 * @param pDbColumnName
	 * @return
	 */
	public static String getFieldShortName(String pDbColumnName) {

		return getColumnNameToShortNameMap().get(pDbColumnName);

	}

	
	/**
	 * List of flight-hour float column types.  Intened to be formatted as 
	 * ex: 1.2 for 1.2 hours
	 */
	public static final List<String> HOURS_FLOATS_COLUMN_LIST = Arrays.asList(
			TOTAL_HOURS, SOLO, SECOND_IN_COMMAND_HOURS,
		    PILOT_IN_COMMAND_HOURS, DUAL_INSTRUCTION_GIVEN_HOURS,
		    DUAL_INSTRUCTION_RECEIVED_HOURS, SIMULATOR_HOURS,		    
		    INSTRUMENT_SIMULATED_HOURS,
		    INSTRUMENT_ACTUAL_HOURS, NIGHT_HOURS, DAY_HOURS,
		    CROSS_COUNTRY_HOURS, MULTI_ENGINE_HOURS,
		    SINGLE_ENGINE_HOURS);
	
	
	
	/**
	 * A list of all the column types - in the default order as they'll appear 
	 * in the main record table on the screen
	 */
	public static final List<String> DEFAULT_COLUMN_DISPLAY_ORDER_LIST = 
		Arrays.asList(DATE_OF_FLIGHT, AIRCRAFT_TYPE, AIRCRAFT_REGISTRATION,
					ARRIVAL_AIRPORT_CODE, DEPARTURE_AIRPORT_CODE,
					LANDINGS_TOTAL_COUNT, LANDINGS_DAY_COUNT,
					LANDINGS_NIGHT_COUNT, SINGLE_ENGINE_HOURS,
					MULTI_ENGINE_HOURS, CROSS_COUNTRY_HOURS, DAY_HOURS,
					NIGHT_HOURS, INSTRUMENT_ACTUAL_HOURS,
					INSTRUMENT_SIMULATED_HOURS, INSTRUMENT_APPROACHES_COUNT,
					INSTRUMENT_APPROACHES_NAMES, SAFETY_PILOT_NAME,
					SIMULATOR_HOURS, DUAL_INSTRUCTION_RECEIVED_HOURS,
					DUAL_INSTRUCTION_GIVEN_HOURS, PILOT_IN_COMMAND_HOURS,
					SECOND_IN_COMMAND_HOURS, SOLO, TOTAL_HOURS, REMARKS);

	
	
    /**
     * getLogBookRecElement
     * 
     * @param pLogBookRec
     * @param pColumnId
     * @return
     */
    public static Object getLogBookRecElement(LogBookRec pLogBookRec,
	    String pColumnId) {

	Object rLogBookRecElement = null;

	if (REMARKS.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getRemarks();

	} else if (TOTAL_HOURS.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getTotalHours();

	} else if (SOLO.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getSoloHours();

	} else if (SECOND_IN_COMMAND_HOURS.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getSicHours();

	} else if (PILOT_IN_COMMAND_HOURS.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getPicHours();

	} else if (DUAL_INSTRUCTION_GIVEN_HOURS.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getDualGivenHours();

	} else if (DUAL_INSTRUCTION_RECEIVED_HOURS.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getDualReceivedHours();

	} else if (SIMULATOR_HOURS.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getSimHours();

	} else if (SAFETY_PILOT_NAME.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getSafetyPilotName();

	} else if (INSTRUMENT_APPROACHES_NAMES.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getIapNames();

	} else if (INSTRUMENT_APPROACHES_COUNT.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getIapCount();

	} else if (INSTRUMENT_SIMULATED_HOURS.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getSimHours();

	} else if (INSTRUMENT_ACTUAL_HOURS.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getInstrumentActualHours();

	} else if (NIGHT_HOURS.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getNightHours();

	} else if (DAY_HOURS.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getDayHours();

	} else if (CROSS_COUNTRY_HOURS.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getxCountryHours();

	} else if (MULTI_ENGINE_HOURS.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getMultiEngineHours();

	} else if (SINGLE_ENGINE_HOURS.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getSingleEngineHours();

	} else if (LANDINGS_NIGHT_COUNT.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getLandingsNightCount();

	} else if (LANDINGS_DAY_COUNT.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getLandingsDayCount();

	} else if (LANDINGS_TOTAL_COUNT.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getLandingsTotalCount();

	} else if (ARRIVAL_AIRPORT_CODE.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getArrivalAirportCode();

	} else if (DEPARTURE_AIRPORT_CODE.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getDepartAirportCode();

	} else if (AIRCRAFT_REGISTRATION.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getAircraftRegistration();

	} else if (AIRCRAFT_TYPE.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getAircraftType();

	} else if (DATE_OF_FLIGHT.equals(pColumnId)) {

	    rLogBookRecElement = pLogBookRec.getFlightDate();

	}

	return rLogBookRecElement;
    }

}
